let list = null

async function get() {
  list = await axios({
    url: 'index/index',
  }).then(res => {
    console.log(res.data.data)
    return res.data.data
  })
  new Vue({
    el: '.shw',
    data: {
      allCate: list.allCate,
      banner: list.banner,
      sideBanner: list.sideBanner,
      allTag: list.allTag,
      allLink: list.allLink,
      token: localStorage.getItem('token'),
      user: localStorage.getItem('user')
        ? JSON.parse(localStorage.getItem('user'))
        : null,
      pic: localStorage.getItem('user')
        ? JSON.parse(localStorage.getItem('user')).icon
        : null,
    },
    filters: {
      www(val) {
        let day = new Date(val).getDate()
        day = day < 10 ? '0' + day : day
        let m = new Date(val).getMonth() + 1
        m = m < 10 ? '0' + m : m
        let y = new Date(val).getFullYear()
        y = y < 10 ? '0' + y : y
        return y + '-' + m + '-' + day
      },
    },
    // conputed: {},
    methods: {
      change(e) {
        console.log(e.target.files[0])
        let fd = new FormData()
        fd.append('file', e.target.files[0])
        axios({
          method: 'POST',
          data: fd,
          url: 'common/upload?type=images',
          headers: { token: localStorage.getItem('token') },
        }).then(res => {
          console.log(res.data.data.savePath)
          this.pic = res.data.data.savePath
        })
      },
      img() {
        this.$refs.file.click()
      },
      rest() {
        this.$refs.form.reset()
      },
      btn() {
        let form = new FormData(this.$refs.form)

        axios({
          method: 'post',
          headers: { token: localStorage.getItem('token') },
          url: 'user/update',
          data: {
            mobile: JSON.parse(localStorage.getItem('user')).userInfo.mobile,
            icon: this.pic,
            address: form.get('address'),
            notes: form.get('notes'),
            sex: form.get('sex'),
            password: JSON.parse(localStorage.getItem('user')).userInfo
              .password,
            id: JSON.parse(localStorage.getItem('user')).userInfo.id,
            birthday: form.get('birthday'),
            username: form.get('username'),
          },
        }).then(function (res) {
          console.log(res)
          layer.msg(res.data.errmsg)
          setTimeout(() => (location.href = '/web-static/user.html'), 1000)
        })
      },

      rem() {
        layer.confirm(
          '确认退出？',
          {
            btn: ['确认', '取消'], //可以无限个按钮
          },
          function (index, layero) {
            //按钮【按钮一】的回调
            localStorage.clear()
            location.href = '/web-static/index.html'
          },
          function (index) {
            //按钮【按钮二】的回调
          },
        )
      },
    },
  })
}
get()
